package com.hzqy.service.statistics;

import com.hzqy.persistence.dao.statistics.ListenUvAndPvDao;
import com.hzqy.service.core.GenericServiceBean;
import com.hzqy.web.vo.statistics.ListenUvAndPvVo;
import com.hzqy.web.vo.statistics.user_video_demand.UserVideoDemandVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ListenUvAndPvServiceBean extends GenericServiceBean<ListenUvAndPvVo, ListenUvAndPvDao, Integer>{
	private static final long serialVersionUID = 1L;
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	
	@Resource
	private ListenUvAndPvDao listenUvAndPvDao;
	
	@Override
	public ListenUvAndPvDao getEntityDao() {
		return listenUvAndPvDao;
	}

	/**
	 * 校园PV和UV统计
	 * @param listenUvAndPvVo
	 * @param curPage
	 * @param pageSize
	 * @return
	 */
	public Map<String, Object> selectSchoolListenUvAndPvList(ListenUvAndPvVo listenUvAndPvVo, int curPage, int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();

		String selectDate = listenUvAndPvVo.getSelectDate();
		if(selectDate==null||selectDate.length()<=0){
			map.put("total", 0);
			map.put("rows", 0);
		}else{
			String databaseNameDate = selectDate.substring(0,4)+selectDate.substring(5,7);
			String databaseName = "itv_weblogs.tmp_user_visit_history_urlid_total_"+databaseNameDate;
			map.put("databaseName",databaseName);
			map.put("selectDate",listenUvAndPvVo.getSelectDate());

			Integer rowCount = 0;
			rowCount = listenUvAndPvDao.selectListenUvAndPvCount(map);
			map.put("total", rowCount);
			if(rowCount > 0 && curPage > 0 && pageSize > 0) {
				map.put("firstResult", (curPage-1)*pageSize);
				map.put("maxResults", pageSize);

				List<ListenUvAndPvVo> results = new ArrayList<ListenUvAndPvVo>();
				results = listenUvAndPvDao.selectListenUvAndPvList(map);
				map.put("rows", results);
			} else {
				map.put("rows", new ArrayList<UserVideoDemandVo>());
			}
		}
		return map;
	}

}
